package com.zjbd.douyangsystem.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zjbd.douyangcommoncore.entity.DyNews;
import com.zjbd.douyangcommoncore.result.Result;
import com.zjbd.douyangcommoncore.service.DyNewsService;
import com.zjbd.douyangcommoncore.vo.DyNewsVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Tag(name = "新闻相关")
@RestController
@RequestMapping("/douyang/system/news")
public class NewsController {

    @Autowired
    private DyNewsService dyNewsService;

    //添加新闻
    @Operation(summary = "添加新闻")
    @PostMapping("/add")
    public Result add(@RequestBody DyNewsVo dyNewsVo){
        log.info("添加新闻：{}",dyNewsVo);
        DyNews dyNews = new DyNews();
        //Vo转换成Entity
        BeanUtil.copyProperties(dyNewsVo,dyNews);
        dyNewsService.save(dyNews);
        return Result.success("添加成功");
    }

}
